<?php
include_once("../configs/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation
require_once("controlHeader.php");					//--> system control header
include_once("Pic.php");							//--> Pic
include_once("InfoClass.php");						//--> Info Class
include_once("Strings.php");						//--> string
require_once("../tools/fckeditor/fckeditor.php") ;

$objOperate 	= new Operation($objSession->session['lan']);			//--> Operation
$objPic			= new Pic($objSession->session['lan'], $uid);			//--> Pic
$objInfoClass 	= new InfoClass($objSession->session['lan'], $uid);		//--> Info Class
$objString 		= new Strings();

$error_message 	= '';
$classid		= 0;

$name			= '';
$summary		= '';

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);

$arrClassid = $objInfoClass->getDir($arrOperate, 5);

$arrDataInfo = $objPic->getFromID($arrOperate, $id);
if(is_array($arrDataInfo)){
	$name 			= $arrDataInfo['name'];
	$classid		= $arrDataInfo['classid'];
	$formatid		= $arrDataInfo['formatid'];
	
	$summary 		= $arrDataInfo['summary'];
	$status 		= $arrDataInfo['status'];
}

if(isset($_POST['Submit'])){
	$classid	= $_POST['classid'];
	$name		= $_POST['name'];
	$summary	= $_POST['summary'];
	$status		= 'wait';
	
	if(empty($name))
		$error_message = 'name should\'t be empty.';
	else if(!$objInfoClass->isLeaf($arrOperate, $classid))
		$error_message = 'class should\'t be leaf category.';
	else if(empty($summary))
		$error_message = 'summary should\'t be empty.';
	else if(strlen($summary) > 1000)
		$error_message = 'summary can\'t more than 1000 chars.';
	else{
		$isReturn = $objPic->edit($arrOperate, $id, $uid, $classid, $name, $objString->strip_selected_tags($summary, $ARR_FILTER_TAG), $status);
		if($isReturn){
			$error_message = 'edit successfully.';
		}else{
			$error_message .= 'edit failure.';
		}
	}
}

/*----- load FCKEditor -----*/
$oFCKeditor = new FCKeditor('summary') ;

$oFCKeditor->Height		= $fckEditorHeight;
$oFCKeditor->BasePath	= $fckBasePath;

$oFCKeditor->Value = $summary;

$fckHtml = $oFCKeditor->CreateHtml() ;

/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_DIR;
$smarty->compile_dir  = COMPILE_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);
$smarty->assign('id',$id);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('arrClassid', $arrClassid);
$smarty->assign('classidS', $classid);
$smarty->assign('name', $name);
$smarty->assign("fckHtml", $fckHtml);

$smarty->display('listPic_Edit.htm');
?>
